struct domain *d = vioapic_domain(vioapic);
struct hvm_irq *hvm_irq = &d->arch.hvm_domain.irq;
union vioapic_redir_entry *pent, ent;
+ int unmasked = 0;
spin_lock(&d->arch.hvm_domain.irq_lock);
}
else
{
+ unmasked = ent.fields.mask;
/* Remote IRR and Delivery Status are read-only. */
ent.bits = ((ent.bits >> 32) << 32) | val;
ent.fields.delivery_status = 0;
ent.fields.remote_irr = pent->fields.remote_irr;
+ unmasked = unmasked && !ent.fields.mask;
}
*pent = ent;
}
spin_unlock(&d->arch.hvm_domain.irq_lock);
+
+ if ( idx == 0 || unmasked )
+ pt_may_unmask_irq(d, NULL);
}
static void vioapic_write_indirect(
}
}
else
+ {
vlapic->hw.disabled &= ~VLAPIC_SW_DISABLED;
+ pt_may_unmask_irq(vlapic_domain(vlapic), &vlapic->pt);
+ }
break;
case APIC_ESR:
val &= vlapic_lvt_mask[(offset - APIC_LVTT) >> 4];
vlapic_set_reg(vlapic, offset, val);
if ( offset == APIC_LVT0 )
+ {
vlapic_adjust_i8259_target(v->domain);
+ pt_may_unmask_irq(v->domain, NULL);
+ }
+ if ( (offset == APIC_LVTT) && !(val & APIC_LVT_MASKED) )
+ pt_may_unmask_irq(NULL, &vlapic->pt);
break;
case APIC_TMICT:
{
vlapic_reset(vlapic);
vlapic->hw.disabled &= ~VLAPIC_HW_DISABLED;
+ pt_may_unmask_irq(vlapic_domain(vlapic), &vlapic->pt);
}
else
{
vlapic->hw.disabled |= VLAPIC_HW_DISABLED;
+ pt_may_unmask_irq(vlapic_domain(vlapic), NULL);
}
}
struct hvm_hw_vpic *vpic, uint32_t addr, uint32_t val)
{
int priority, cmd, irq;
- uint8_t mask;
+ uint8_t mask, unmasked = 0;
vpic_lock(vpic);
/* Clear edge-sensing logic. */
vpic->irr &= vpic->elcr;
+ unmasked = vpic->imr;
/* No interrupts masked or in service. */
vpic->imr = vpic->isr = 0;
{
case 0:
/* OCW1 */
+ unmasked = vpic->imr & (~val);
vpic->imr = val;
break;
case 1:
vpic_update_int_output(vpic);
vpic_unlock(vpic);
+
+ if ( unmasked )
+ pt_may_unmask_irq(vpic_domain(vpic), NULL);
}
static uint32_t vpic_ioport_read(struct hvm_hw_vpic *vpic, uint32_t addr)
void pt_update_irq(struct vcpu *v)
{
struct list_head *head = &v->arch.hvm_vcpu.tm_list;
- struct periodic_time *pt, *earliest_pt = NULL;
+ struct periodic_time *pt, *temp, *earliest_pt = NULL;
uint64_t max_lag = -1ULL;
int irq, is_lapic;
spin_lock(&v->arch.hvm_vcpu.tm_lock);
- list_for_each_entry ( pt, head, list )
+ list_for_each_entry_safe ( pt, temp, head, list )
{
- if ( pt->pending_intr_nr && !pt_irq_masked(pt) &&
- ((pt->last_plt_gtime + pt->period) < max_lag) )
+ if ( pt->pending_intr_nr )
{
- max_lag = pt->last_plt_gtime + pt->period;
- earliest_pt = pt;
+ if ( pt_irq_masked(pt) )
+ {
+ /* suspend timer emulation */
+ list_del(&pt->list);
+ pt->on_list = 0;
+ }
+ else
+ {
+ if ( (pt->last_plt_gtime + pt->period) < max_lag )
+ {
+ max_lag = pt->last_plt_gtime + pt->period;
+ earliest_pt = pt;
+ }
+ }
}
}
if ( pt->on_list )
list_del(&pt->list);
pt->on_list = 0;
+ pt->pending_intr_nr = 0;
pt_unlock(pt);
/*
void pt_adjust_global_vcpu_target(struct vcpu *v)
{
- struct pl_time *pl_time = &v->domain->arch.hvm_domain.pl_time;
+ struct pl_time *pl_time;
int i;
if ( v == NULL )
return;
+ pl_time = &v->domain->arch.hvm_domain.pl_time;
+
spin_lock(&pl_time->vpit.lock);
pt_adjust_vcpu(&pl_time->vpit.pt0, v);
spin_unlock(&pl_time->vpit.lock);
pt_adjust_vcpu(&pl_time->vhpet.pt[i], v);
spin_unlock(&pl_time->vhpet.lock);
}
+
+
+static void pt_resume(struct periodic_time *pt)
+{
+ if ( pt->vcpu == NULL )
+ return;
+
+ pt_lock(pt);
+ if ( pt->pending_intr_nr && !pt->on_list )
+ {
+ pt->on_list = 1;
+ list_add(&pt->list, &pt->vcpu->arch.hvm_vcpu.tm_list);
+ vcpu_kick(pt->vcpu);
+ }
+ pt_unlock(pt);
+}
+
+void pt_may_unmask_irq(struct domain *d, struct periodic_time *vlapic_pt)
+{
+ int i;
+
+ if ( d )
+ {
+ pt_resume(&d->arch.hvm_domain.pl_time.vpit.pt0);
+ pt_resume(&d->arch.hvm_domain.pl_time.vrtc.pt);
+ for ( i = 0; i < HPET_TIMER_NUM; i++ )
+ pt_resume(&d->arch.hvm_domain.pl_time.vhpet.pt[i]);
+ }
+
+ if ( vlapic_pt )
+ pt_resume(vlapic_pt);
+}
#define pt_global_vcpu_target(d) \
((d)->arch.hvm_domain.i8259_target ? : (d)->vcpu ? (d)->vcpu[0] : NULL)
+void pt_may_unmask_irq(struct domain *d, struct periodic_time *vlapic_pt);
+
/* Is given periodic timer active? */
-#define pt_active(pt) ((pt)->on_list)
+#define pt_active(pt) ((pt)->on_list || (pt)->pending_intr_nr)
/*
* Create/destroy a periodic (or one-shot!) timer.